package com.framework.controller;

import com.framework.entity.flow.FlowAccount;
import com.framework.exception.util.RespResult;
import com.framework.service.FlowAccountService;
import com.framework.service.NoticeReadService;
import com.framework.view.FlowNoticeTerView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;

/**
 * 功能描述: 通知控制器
 *
 * @author ck
 * @date 2018/10/22 13:46
 */
@RestController
@Api(value="通知消息模块",tags={"通知消息模块"})
@RequestMapping(value = "notice")
public class NoticeController {

	@Autowired
	private NoticeReadService noticeReadService;
	@Autowired
	private FlowAccountService flowAccountService;

	/**
	 * 消息通知数量
	 * @param token
	 * @return
	 */
	@GetMapping("user/getMessageNoticeCount")
	@ApiOperation("消息通知数量")
	public RespResult getMessageNoticeCount(String token) {
		Map<String,Object> map = noticeReadService.getMessageNotice(token);
		return RespResult.ok(map);
	}

	/**
	 * 得到分配通知的详情
	 * @param noticeTerNo
	 * @return
	 */
	@GetMapping("user/getNoticeTerInfo")
	@ApiOperation("得到分配通知的详情")
	@ApiImplicitParams({
			@ApiImplicitParam(name="noticeTerNo",value="机具分配通知id",dataType="string", paramType = "query",required = true)
	})
	public RespResult getNoticeTInfo(String noticeTerNo) {
		Map<String,Object> map = noticeReadService.getNoticeTerInfo(noticeTerNo);
		return RespResult.ok(map);
	}

	/**
	 * 获取分配机具通知列表
	 * @param token
	 * @return
	 */
	@GetMapping("user/getNoticeTerList")
	@ApiOperation("获取分配机具通知列表")
	public RespResult getNoticeTerList(String token) {
		List<FlowNoticeTerView> list = noticeReadService.getNoticeTerList(token);
		return RespResult.ok().put("list",list);
	}

	/**
	 * 百易助手通知列表
	 * @param token
	 * @return
	 */
	@GetMapping("user/queryAssList")
	@ApiOperation("百易助手通知列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name="pageNo",value="分页参数 0开始",dataType="int", paramType = "query",required = true)
	})
	public RespResult queryAssList(String token,Integer pageNo) {
		List<FlowAccount> list = flowAccountService.queryFlowAccountList(token,new FlowAccount(),pageNo);
		return RespResult.ok().put("list",list);
	}

	/**
	 * 接受终端操作
	 * @param token
	 * @param noticeTerNo
	 * @return
	 */
	@PostMapping("user/acceptTer")
	@ApiOperation("百易助手-接受终端操作")
	@ApiImplicitParams({
			@ApiImplicitParam(name="noticeTerNo",value="机具分配通知id",dataType="string", paramType = "query",required = true)
	})
	public RespResult acceptTer(String token,String noticeTerNo) {
		noticeReadService.acceptTer(token,noticeTerNo);
		return RespResult.ok();
	}

	/**
	 * 获取系统通知信息列表
	 * @param token
	 * @return
	 */
	@GetMapping("user/querySysNoticeList")
	@ApiOperation("获取系统通知信息列表")
	public RespResult querySysNoticeList(String token) {
		List<Map<String,Object>> list = noticeReadService.querySysNoticeList(token);
		return RespResult.ok().put("list",list);
	}

	/**
	 * 查询是否有需要接受的机器
	 * @param token
	 * @return
	 */
	@GetMapping("user/isAcceptTer")
	@ApiOperation("查询是否有需要接受的机器")
	public RespResult isAcceptTer(String token) {
		boolean isAccept = noticeReadService.isAcceptTer(token);
		return RespResult.ok().put("isAccept",isAccept);
	}


	/**
	 * 获取系统通知信息列表
	 * @param token
	 * @return
	 */
	@GetMapping("user/queryCarouselNoticeList")
	@ApiOperation("获取系统通知信息轮播")
	public RespResult queryCarouselNoticeList(String token) {
		List<Map<String,Object>> list = noticeReadService.queryCarouselNoticeList(token);
		return RespResult.ok().put("list",list);
	}

}
